<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *会员分组
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
);

//红包记录
if($_RQ['op']=='list'){
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
	$params['workerid']=intval($_RQ['id']);
	if(!$_RQ['id']){
		exi('请选择员工！','error');
	}
	if($_RQ['ishuo']){
		$params['workerid']=pdo_getcolumn('jy_worker_ewm_worker',array('merchid'=>$_SESSION['onemerchid'],'id'=>intval($_RQ['id']),'uniacid'=>$_SESSION['uniacid']),'workerid');
	}
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(!empty($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_scrm_worker_giftlog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$types=array('送币','送优惠券','送抽奖机会');
		$credit_types=credit_types();
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['reward']=json_decode($item['reward'],true);
			$item['rewardinfo']='';
			foreach($item['reward'] as $rv){
				$item['rewardinfo'] .=$types[$rv['type']].',';
				if(!$rv['type']){
					$item['rewardinfo'] .=$credit_types[$rv['credit_type']].' '.$rv['credit_num'].'个';
				}elseif($rv['type']==1){
					$title=pdo_getcolumn('jy_weishop_coupon',array('id'=>$rv['couponid'],'uniacid'=>$_SESSION['uniacid']),'title');
					$item['rewardinfo'] .=$title.' '.$rv['coupon_num'].'张';
				}elseif($rv['type']==2){
					$title=pdo_getcolumn('jy_weishop_game',array('id'=>$rv['jy_bigwheelid'],'uniacid'=>$_SESSION['uniacid']),'title');
					$item['rewardinfo'] .=$title.' '.$rv['game_num'].'次';
				}
				$item['rewardinfo'] .=';';
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'workerid','title'=>'所属员工','type'=>'select','options'=>'workers','option_title'=>'name'),
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('name'=>'status','title'=>'送礼状态','type'=>'radio','options'=>'status'),
			array('name'=>'rewardinfo','title'=>'奖品内容','type'=>'string'),
			array('name'=>'createtime','title'=>'送礼时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>13,'title'=>'所属会员ID','name'=>'mid','action'=>'core/member.get_member/'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'select','options'=>'status'),
		)
	);
	$return['workers']=pdo_getall('jy_scrm_worker',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),array('id','name'),'id');
	$return['status']=array('待送礼','已送出');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_scrm_worker_giftlog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}